﻿using System;
using System.Collections.Generic;

using System.Text;
using RebellionII.GameObjects;
using System.Xml;
using Microsoft.Xna.Framework.Graphics;


namespace RebEngine
{

    /// <summary>
    /// A simple class that stores the Game Settings in. Loaded from GameSettings.xml
    /// </summary>
    public class GameSettings
    {
        public bool IsFullScreen { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int SoundVolume { get; set; }
        public int MusicVolume { get; set; }
        public int NetPort { get; set; }
        public int ChanceJediBonus { get; set; }
        public int ChanceTroopBonus { get; set; }
        public int ChanceShipBonus { get; set; }
        public int ChanceFacilityBonus { get; set; }
        public int CoreMaxFacilities { get; set; }
        public int CoreMinFacilities { get; set; }
        public int MidMaxFacilities { get; set; }
        public int MidMinFacilities { get; set; }
        public int RimMaxFacilities { get; set; }
        public int RimMinFacilities { get; set; }
        public TeamName TeamFavoured { get; set; }
        public bool DoubleStartingPlanets { get; set; }
        public string PlayerName { get; set; }
        public bool DebugMode { get; set; }
        public int MinimumEnergy { get; set; }

        /// <summary>
        /// Default Constructor
        /// </summary>
        public GameSettings()
        {
            
        }

        /// <summary>
        /// Used to Load a default set of settings for XML Saving
        /// </summary>
        /// <param name="defaultSettings">Not used</param>
        public GameSettings(bool defaultSettings)
        {
            IsFullScreen = true;
            Width = 1680;
            Height = 1050;
            SoundVolume = 100;
            MusicVolume = 100;
            NetPort = 65012;
            ChanceFacilityBonus = 4;
            ChanceJediBonus = 2;
            ChanceShipBonus = 4;
            ChanceTroopBonus = 4;
            CoreMaxFacilities = 12;
            CoreMinFacilities = 6;
            MidMaxFacilities = 15;
            MidMinFacilities = 4;
            RimMaxFacilities = 16;
            RimMinFacilities = 2;
            TeamFavoured = TeamName.Default;
            DoubleStartingPlanets = false;
        }

        /// <summary>
        /// Reads the GameSettings.xml file into this class
        /// </summary>
        public void ReadXMLintoOptions()
        {
            XmlTextReader settingsDocument = new XmlTextReader("GameSettings.xml");
            settingsDocument.Read();

            while (settingsDocument.Read())
            {
                XmlNodeType nType = settingsDocument.NodeType;
                if (nType == XmlNodeType.Element)
                {

                    switch (settingsDocument.Name.ToString())
                    {
                        case "IsFullScreen":
                            IsFullScreen = settingsDocument.ReadElementContentAsBoolean();
                            break;
                        case "MinimumEnergy":
                            MinimumEnergy = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "DoubleStartingPlanets":
                            DoubleStartingPlanets = settingsDocument.ReadElementContentAsBoolean();
                            break;
                        case "Width":
                            Width = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "Height":
                            Height = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "ChanceFacilityBonus":
                            ChanceFacilityBonus = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "ChanceJediBonus":
                            ChanceJediBonus = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "ChanceShipBonus":
                            ChanceShipBonus = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "ChanceTroopBonus":
                            ChanceTroopBonus = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "CoreMaxFacilities":
                            CoreMaxFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "CoreMinFacilities":
                            CoreMinFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "NetPort":
                            NetPort = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "MusicVolume":
                            MusicVolume = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "SoundVolume":
                            SoundVolume = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "MidMaxFacilities":
                            MidMaxFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "MidMinFacilities":
                            MidMinFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "RimMaxFacilities":
                            RimMaxFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "RimMinFacilities":
                            RimMinFacilities = settingsDocument.ReadElementContentAsInt();
                            break;
                        case "TeamFavoured":
                            string team = settingsDocument.ReadElementContentAsString();
                            if (team == "Empire")
                                TeamFavoured = TeamName.Empire;
                            if (team == "Default")
                                TeamFavoured = TeamName.Default;
                            if (team == "Alliance")
                                TeamFavoured = TeamName.Alliance;
                            break;
                        case "PlayerName":
                            PlayerName = settingsDocument.ReadElementContentAsString();
                            break;
                        case "DebugMode":
                            DebugMode = settingsDocument.ReadElementContentAsBoolean();
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}
